package com.caeit.controllers.bigscreen

import cn.hutool.json.JSONUtil
import com.caeit.controllers.TestControllerBase
import com.caeit.model.bigscreen.BigscreenConfig
import org.junit.Assert
import org.junit.jupiter.api.Test
import org.springframework.http.MediaType
import org.springframework.security.test.context.support.WithMockUser
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders
import org.springframework.test.web.servlet.result.MockMvcResultHandlers
import java.net.URI


class BigscreenConfigControllerTest : TestControllerBase() {

    @Test
    @WithMockUser(username = "ypt", roles = ["admin"])
    fun paginQuery() {
        val res = mvc.perform(
            MockMvcRequestBuilders.get(URI.create("/api/bigscreenConfig/paginQuery")).accept(MediaType.ALL)
                .header("Authorization",adminToken).param("name", "大屏")
        ).andDo(MockMvcResultHandlers.print())
            .andReturn()

        Assert.assertTrue("paginQuery接口测试失败", res.response.status == 200)
    }

    @Test
    @WithMockUser(username = "ypt", roles = ["admin"])
    fun save1() {
        val bigscreenConfig = BigscreenConfig()
        bigscreenConfig.category = 0
        bigscreenConfig.name = "大屏测试"
        bigscreenConfig.mainJson = "{'aaa': 'bbb'}"
        bigscreenConfig.status = 0

        val requestJson = JSONUtil.toJsonStr(bigscreenConfig)
        val res = mvc.perform(
            MockMvcRequestBuilders.post(URI.create("/api/bigscreenConfig/save")).accept(MediaType.ALL)
                .header("Authorization",adminToken).contentType(MediaType.APPLICATION_JSON).content(requestJson)
        ).andDo(MockMvcResultHandlers.print())
            .andReturn()

        Assert.assertTrue("save接口测试失败", res.response.status == 201)
    }

    @Test
    @WithMockUser(username = "ypt", roles = ["admin"])
    fun save2() {
        val bigscreenConfig = BigscreenConfig()
        bigscreenConfig.category = 0
        bigscreenConfig.name = "大屏测试"
        bigscreenConfig.mainJson = "{'aaa': 'bbb'}"
        bigscreenConfig.status = 1

        val requestJson = JSONUtil.toJsonStr(bigscreenConfig)
        val res = mvc.perform(
            MockMvcRequestBuilders.post(URI.create("/api/bigscreenConfig/save")).accept(MediaType.ALL)
                .header("Authorization",adminToken).contentType(MediaType.APPLICATION_JSON).content(requestJson)
        ).andDo(MockMvcResultHandlers.print())
            .andReturn()

        Assert.assertTrue("save接口测试失败", res.response.status == 406)
    }

    @Test
    @WithMockUser(username = "ypt", roles = ["admin"])
    fun queryEnableData() {
        val res = mvc.perform(
            MockMvcRequestBuilders.get(URI.create("/api/bigscreenConfig/queryEnableData")).accept(MediaType.ALL)
                .header("Authorization",adminToken)
        ).andDo(MockMvcResultHandlers.print())
            .andReturn()

        Assert.assertTrue("queryEnableData接口测试失败", res.response.status == 200)
    }
}